interface IGoods {

    getPrice:()=>number,

    getName:()=>string,

}


// 类使用implements关键字，实现接口。实现接口之后，必须实现接口中定义的方法。
class Animal implements IGoods {

    private name:string;

    private age:number;

    constructor(name:string,age:number) {
        this.name = name;
        this.age = age;
    }

    getPrice() {
        if (this.age <= 10) {
            return 1000;
        } else {
            return 10;
        }
    }

    getName() {
        return this.name;
    }

}


class SuperMark {

    private name:string;

    constructor(name:string) {
        this.name = name;
    }

    sell(goods:IGoods):void {
        console.log(`${this.name}销售了：${goods.getName()}，赚了：${goods.getPrice()}元！`)
    }

}

let cat:Animal = new Animal("哆啦A梦",1);
let dog:Animal = new Animal("苏比狗",1);

let superMark:SuperMark = new SuperMark("沃尔玛");

superMark.sell(cat);
superMark.sell(dog);

